<template>
    <div class="ele-body">
      <el-card shadow="never">
        <!-- 搜索表单 -->
        <el-form
          :model="where"
          label-width="77px"
          class="ele-form-search"
          @keyup.enter.native="reload"
          @submit.native.prevent>
          <el-row :gutter="15">
            <el-col :lg="5" :md="12" style="">
              <el-form-item label="商品编码:">
                <el-input
                  clearable
                  v-model="where.chineseName"
                  placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :md="5" :sm="12">
            <el-form-item label="库存日期:">
                <el-date-picker v-model="where.riqiBegin" type="date" format='yyyy-MM-dd' value-format='yyyy-MM-dd' placeholder="选择日期" clearable class="ele-fluid"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :md="5" :sm="12" v-if="false">
            <el-form-item label="结束日期:">
                <el-date-picker v-model="where.riqiEnd" type="date" format='yyyy-MM-dd' value-format='yyyy-MM-dd' placeholder="选择日期" clearable class="ele-fluid"></el-date-picker>
            </el-form-item>
          </el-col>

                <el-col :lg="4" :md="12">
              <div class="ele-form-actions">
                <el-button
                  type="primary"
                  icon="el-icon-search"
                  class="ele-btn-icon"
                  size="small"
                  @click="reload">查询
                </el-button>
                <el-button @click="reset" size="small">重置</el-button>
              </div>
            </el-col>
          </el-row>
        </el-form>
        <!-- 数据表格 -->
        <ele-pro-table
          ref="table"
          :where="where"
          :datasource="dataList"
          :columns="columns"
          :selection.sync="selection"
          :needPage="false"
          height="calc(100vh - 235px)">
          <!-- 表头工具栏 -->
          <template slot="toolbar" v-if="false">
            <el-button
              size="small"
              type="primary"
              icon="el-icon-plus"
              class="ele-btn-icon"
              @click="openEdit(null)"
              v-if="permission.includes('sys:c37infdsfrkzyjl:add')">添加
            </el-button>
            <el-button
              size="small"
              type="danger"
              icon="el-icon-delete"
              class="ele-btn-icon"
              @click="removeBatch"
              v-if="permission.includes('sys:c37infdsfrkzyjl:dall')">删除
            </el-button>
          </template>
          <template slot="vlotno" slot-scope="{row}">
            <a @click="show(row)" style="color:blue;cursor:pointer">{{row.vlotno}}</a>
          </template>
          <!-- 操作列 -->
          <template slot="action" slot-scope="{row}">
            <el-link
              type="primary"
              :underline="false"
              icon="el-icon-edit"
              @click="openEdit(row)"
              v-if="permission.includes('sys:c37infdsfrkzyjl:edit')">修改
            </el-link>
            <el-popconfirm
              class="ele-action"
              title="确定要删除此吗？"
              @confirm="remove(row)">
              <el-link
                type="danger"
                slot="reference"
                :underline="false"
                icon="el-icon-delete"
                v-if="permission.includes('sys:c37infdsfrkzyjl:delete')">删除
              </el-link>
            </el-popconfirm>
          </template>
        </ele-pro-table>
      </el-card>
      <StockDetail :dataItem="current" :kcrq="where.riqiBegin" :visible.sync="showDetail"></StockDetail>
    </div>
  </template>

  <script>
  import { mapGetters } from "vuex";
  import moment from 'moment';
  import StockDetail from './stockdetail.vue'

  export default {
    name: 'ExamC37InfDsfRkzyjl',
    components:{StockDetail},
    computed: {
      ...mapGetters(["permission"]),
    },
    data() {
      return {
        // 表格数据接口
        url: '/c37infkcspphhw/kcbd',
        // 表格列配置
        columns: [
        {
          prop: 'invcode',
          label: '物料编码',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'invname',
          label: '物料名称',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: 'vlotno',
          label: '批号',
          showOverflowTooltip: true,
          minWidth: 130,
          align: 'center',
          slot:'vlotno'
        },
        {
          prop: 'nonhandnum',
          label: 'NC库存数量',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'jztnum',
          label: '九州通库存数量',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'diffnum',
          label: '差异数量',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        // {
        //   prop: 'ssxkcyr',
        //   label: '',
        //   showOverflowTooltip: true,
        //   minWidth: 100,
        //   align: 'center'
        // },
        // {
        //   prop: 'bhgNum',
        //   label: '',
        //   showOverflowTooltip: true,
        //   minWidth: 100,
        //   align: 'center'
        // },
        // {
        //   prop: 'chulFanga',
        //   label: '',
        //   showOverflowTooltip: true,
        //   minWidth: 100,
        //   align: 'center'
        // },
        // {
        //   prop: 'wenkWay',
        //   label: '',
        //   showOverflowTooltip: true,
        //   minWidth: 100,
        //   align: 'center'
        // },
        // {
        //   prop: 'jushouReason',
        //   label: '',
        //   showOverflowTooltip: true,
        //   minWidth: 100,
        //   align: 'center'
        // },
        // {
        //   prop: 'yansRlt',
        //   label: '',
        //   showOverflowTooltip: true,
        //   minWidth: 100,
        //   align: 'center'
        // },
        // {
        //   prop: 'num',
        //   label: '',
        //   showOverflowTooltip: true,
        //   minWidth: 100,
        //   align: 'center'
        // },
        // {
        //   prop: 'zhijStaff',
        //   label: '',
        //   showOverflowTooltip: true,
        //   minWidth: 100,
        //   align: 'center'
        // },
        // {
        //   prop: 'createTime',
        //   label: '创建时间',
        //   sortable: 'custom',
        //   showOverflowTooltip: true,
        //   minWidth: 160,
        //   align: 'center',
        //   formatter: (row, column, cellValue) => {
        //     return this.$util.toDateString(cellValue);
        //   }
        // },
        // {
        //   prop: 'updateTime',
        //   label: '更新时间',
        //   sortable: 'custom',
        //   showOverflowTooltip: true,
        //   minWidth: 160,
        //   align: 'center',
        //   formatter: (row, column, cellValue) => {
        //     return this.$util.toDateString(cellValue);
        //   }
        // },
        // {
        //   columnKey: 'action',
        //   label: '操作',
        //   width: 150,
        //   align: 'center',
        //   resizable: false,
        //   slot: 'action',
        //   fixed: "right"
        // }
      ],
        // 表格搜索条件
        where: {riqiBegin:moment(new Date()).format("YYYY-MM-DD"),riqiEnd:new Date()},
        dataList:[],
        // 表格选中数据
        selection: [],
        // 当前编辑数据
        current: null,
        // 是否显示编辑弹窗
        showEdit: false,
        showDetail:false,
      };
    },
    mounted() {
      //this.loadData();
    },
    methods: {
    dateFormat(row, column,cellValue) {
    const daterc = row[column.property]
    if(daterc !=null){
        return moment(cellValue).format("YYYY-MM-DD")
      }
    },
    show(row){
      this.current = row;
      this.showDetail = true;
    },
    loadData(){
      const loading = this.$loading({lock: true});
      let url = "/c37infkcspphhw/kcbd?page=1&limit=20000000";
      let param = "";
      Object.keys(this.where).forEach(key=>{
        if(this.where[key] && this.where[key]!="")
        {
          param+="&"+key+"="+this.where[key];
        }
      });
      url = url+param;
      this.$http.get(url).then(res => {
        loading.close();
        this.dataList = res.data.data;
        //console.log(this.dataList);
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
    getFromDate() {
      const timeOne = new Date()
      const year = timeOne.getFullYear()
      let month = timeOne.getMonth()
      let day = 1
      //month = month < 10 ? '0' + month : month
      //day = day < 10 ? '0' + day : day
      ///const NOW_MONTHS_AGO = `${year}-${month}-${day}`
      return new Date(year,month,day);
    },
    statusFormat(row, column,cellValue) {
        const daterc = row[column.property]
        if(daterc !=null){
            return cellValue.trim()=="N"?"已同步":"未同步";
            }
    },
      /* 刷新表格 */
      reload() {
        //this.$refs.table.reload({where: this.where});
        this.loadData();
      },
      /* 重置搜索 */
      reset() {
        this.where = {riqiBegin:moment(new Date()).format("YYYY-MM-DD"),riqiEnd:new Date()};
        this.reload();
      },
      /* 显示编辑 */
      openEdit(row) {
        this.current = row;
        this.showEdit = true;
      },
      /* 删除 */
      remove(row) {
        const loading = this.$loading({lock: true});
        this.$http.delete('/c37infdsfrkzyjl/delete', {id: row.id}).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      },
      /* 批量删除 */
      removeBatch() {
        if (!this.selection.length) {
          this.$message.error('请至少选择一条数据');
          return;
        }
        this.$confirm('确定要删除选中的吗?', '提示', {
          type: 'warning'
        }).then(() => {
          const loading = this.$loading({lock: true});
          this.$http.delete('/c37infdsfrkzyjl/delete', {id: this.selection.map(d => d.id)}).then(res => {
            loading.close();
            if (res.data.code === 0) {
              this.$message.success(res.data.msg);
              this.reload();
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            loading.close();
            this.$message.error(e.message);
          });
        }).catch(() => {
        });
      },
    }
  }
  </script>

  <style scoped>
  </style>
